#!/usr/bin/env python3
"""
创建应用图标
"""
from PIL import Image, ImageDraw, ImageFont
import os

def create_icon():
    """创建应用图标"""
    # 创建图标目录
    os.makedirs('assets', exist_ok=True)
    
    # 创建512x512的图标
    size = 512
    img = Image.new('RGBA', (size, size), (255, 255, 255, 0))
    draw = ImageDraw.Draw(img)
    
    # 绘制背景圆形
    margin = 20
    draw.ellipse([margin, margin, size-margin, size-margin], 
                 fill=(52, 152, 219, 255), outline=(41, 128, 185, 255), width=4)
    
    # 绘制文字 "PM" (Parameter Management)
    try:
        # 尝试使用系统字体
        font = ImageFont.truetype("/System/Library/Fonts/Arial.ttf", 200)
    except:
        # 如果找不到字体，使用默认字体
        font = ImageFont.load_default()
    
    # 计算文字位置
    text = "PM"
    bbox = draw.textbbox((0, 0), text, font=font)
    text_width = bbox[2] - bbox[0]
    text_height = bbox[3] - bbox[1]
    
    x = (size - text_width) // 2
    y = (size - text_height) // 2 - 20
    
    # 绘制文字
    draw.text((x, y), text, fill=(255, 255, 255, 255), font=font)
    
    # 保存图标
    img.save('assets/icon.png')
    print("✅ 图标已创建: assets/icon.png")
    
    # 创建不同尺寸的图标
    sizes = [16, 32, 64, 128, 256, 512]
    for s in sizes:
        resized = img.resize((s, s), Image.Resampling.LANCZOS)
        resized.save(f'assets/icon_{s}.png')
    
    print("✅ 多尺寸图标已创建")

if __name__ == "__main__":
    create_icon()
